package xyz.zhzby.cyzx.acl.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import xyz.zhzby.cyzx.acl.service.IndexService;
import xyz.zhzby.cyzx.security.entity.User;
import xyz.zhzby.cyzx.security.util.CyzxSecurityContextHolder;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;

import java.util.List;
import java.util.Map;

/**
 * @author zby
 * @date 2021/12/07
 */
@RestController
@RequestMapping("/acl/index")
//@CrossOrigin
public class IndexController {

    @Autowired
    private IndexService indexService;

    @ApiOperation("根据token获取用户信息")
    @GetMapping("/info")
    public RestResponse<Map<String, Object>> info() {
        return indexService.getUserInfo();
    }

    @ApiOperation("获取菜单")
    @GetMapping("/menu")
    public RestResponse<List<JSONObject>> getMenu() {
        User subject = CyzxSecurityContextHolder.getSubject();
        List<JSONObject> permissionList = indexService.getMenu(subject);
        return RestResponse.success(permissionList);
    }

}
